package com.ptone.messagecenter.modules.msg.kafka.controller;

import com.ptone.messagecenter.common.base.Result;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.support.Acknowledgment;
import org.springframework.stereotype.Component;


@Component
@Slf4j
public class ConsumerController {

    @KafkaListener(topics = {"${consumer.topicName}"}, containerFactory = "ackContainerFactory")
    public Result<Boolean> listen(ConsumerRecord<?, ?> record, Acknowledgment ack) {
        try {
            String key = (String) record.key();
            String value = (String) record.value();
            log.trace("消息key：{}", key);
            log.trace("消息value：{}", value);

            //TODO


            ack.acknowledge();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Result.success(true);
    }
}
